﻿using JinfuyuanProject.Entity.Models;
using JinfuyuanProject.Entity.ViewModels;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace JinfuyuanProject.Entity
{
    public class JinfuyuanMongoDbContext
    {
        private readonly IMongoDatabase _database;

        public JinfuyuanMongoDbContext()
        {
            // MongoDB 连接字符串
            try
            {
                //string connectionString = "mongodb://192.168.1.2:27017";
                string connectionString = ConfigurationManager.AppSettings["mongo"];
                string databaseName = "Jinfuyuan2025";
                var client = new MongoClient(connectionString);
                _database = client.GetDatabase(databaseName);
            }
            catch (Exception ex)
            {
                // 处理异常（例如记录日志、重新抛出异常等）
                Console.WriteLine($"MongoDB 连接失败: {ex.Message}");
            }
        }

        // MongoDB 集合对应实体
        public IMongoCollection<MParturient> Parturients => _database.GetCollection<MParturient>("Parturients");
        // 继续为其他实体添加集合...
    }
}